<template>
  <div>
    <tableComponents
      :isShow="false"
      @toAdd="showEditDialog"
      addText="添加产品"
      :isHaveExport="false"
      :isHavePagination="false"
    >
      <template v-slot:table>
        <el-table
          v-loading="loading"
          :data="list"
          stripe
          header-row-class-name="head_color"
          tooltip-effect="dark"
          style="width: 99.8%"
        >
          <el-table-column label="标题" min-width="80">
            <template slot-scope="scope">{{ scope.row.title }}</template>
          </el-table-column>

          <el-table-column label="天数" min-width="50">
            <template slot-scope="scope">{{ scope.row.day }}</template>
          </el-table-column>

          <el-table-column label="金额" min-width="50">
            <template slot-scope="scope">{{ scope.row.price }}</template>
          </el-table-column>

          <el-table-column label="收益千分比" min-width="50">
            <template slot-scope="scope">{{ scope.row.income || 0}}‰</template>
          </el-table-column>
          <el-table-column label="水滴收益千分比" min-width="50">
            <template slot-scope="scope">{{ scope.row.waterdrop || 0 }}‰</template>
          </el-table-column>
          <el-table-column label="冻结usdt千分比" min-width="50">
            <template slot-scope="scope">{{ scope.row.freeze || 0}}‰</template>
          </el-table-column>
          <el-table-column label="操作" align="center" min-width="100">
            <template slot-scope="scope">
              <el-button
                :loading="$store.state.isLoading"
                size="mini"
                type="primary"
                @click="showEditDialog(scope.row.id)"
              >编辑</el-button>
              <el-button
                :loading="$store.state.isLoading"
                size="mini"
                @click="deleteNew(scope.$index, scope.row.id)"
                type="danger"
              >删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </template>
    </tableComponents>
    <myEdit @parent="reload" :show.sync="myshow" :editId="editId" :clickNum="clickNum"></myEdit>
  </div>
</template>
<script>
import myEdit from "@/components/dapp/dapp_product_edit.vue";
export default {
  data() {
    return {
      show: false,
      myshow: false,
      loading: false,
      list: [],
      editId: "",
      clickNum: 1
    };
  },
  components: {
    myEdit
  },
  methods: {
    handleSwitch(val, id) {
      //审核
      var params = {};
      params["id"] = id;
      val == true ? (params["is_show"] = 1) : (params["is_show"] = 0);
      this.$api.getCoin.lockCoinMachine(params);
    },

    showAddDialog() {
      this.show = true;
    },

    getNewsAll(data) {
      this.loading = true;
      var params = {};
      data = data || {};
      params = data;
      this.$api.getDapp.getDappProductList(params).then(res => {
        if (res.data.code == 200) {
          this.list = res.data.result;
        }
        this.loading = false;
      });
    },

    deleteNew(index, id) {
      this.$swal({
        title: "您确定要删除这条信息吗",
        text: "删除后将无法恢复，请谨慎操作！",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "是的，我要删除",
        cancelButtonText: "容我三思"
      }).then(willDelete => {
        if (willDelete.value) {
          var data = { id: id };
          this.$api.getDapp.delDappProduct(data).then(res => {
            if (res.data.code == 200) {
              this.$swal("删除成功！", "您已经删除了这条信息。", "success");
              this.getNewsAll();
            } else {
              this.$swal("删除失败！", "出错啦！", "success");
            }
          });
        }
      });
    },
    showEditDialog(id) {
      this.myshow = true;
      this.editId = id;
      this.clickNum++;
    },
    reload() {
      this.getNewsAll();
    }
  },

  created() {
    this.getNewsAll();
  },
  computed: {},
  watch: {
    $route() {
      var params = this.searchAll;
      params.page = this.$route.query.page || 1;
      params.page_size = this.pageSize;
      this.getNewsAll(params);
      this.currentPage = Number(this.$route.query.page) || 1;
    }
  }
};
</script>

<style lang="less" scoped>
thead > tr > th {
  height: 45px;
  line-height: 45px;
}
td,
th {
  border: 1px solid #e1e3e4;
  font-size: 12px;
}
th {
  background: #f8f8f8;
  font-weight: normal;
  color: #323437;
}
td {
  height: 75px;
  color: #000;
}
.caozuo {
  padding-left: 50px;
}
.pl {
  padding-left: 15px;
}
.chkBox {
  display: block;
  margin: 0 auto;
  width: 18px;
  height: 18px;
  background: #fff;
}
.aBtn_1 {
  padding: 10px;
}
</style>
